#!/bin/bash
read -p "输入你的名字: " name
read -p "输入端口（不要和别人重复）: " port

cat > docker-compose.yml <<EOF
services:
  openresty:
    image: registry.intsig.net/cs_hw/openrestry:leon-v1
    container_name: bee-by-$name
    entrypoint: /bin/sh -c "echo 'sandbox' > /usr/local/openresty/nginx/conf/product_env.txt && /usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx_test.conf  -g 'daemon off;'"
    ports:
      - "$port:80"
    volumes:
      - ./ngx_conf:/usr/local/openresty/nginx/conf

EOF

echo "COMPOSE_PROJECT_NAME=bee-by-$name" >.env

curl -s -o ngx_conf/nginx_test.conf https://gitee.com/leon19910505/ohmyzsh/raw/master/bee-project/nginx_test.conf
curl -s -o ngx_conf/nginx_pro.conf https://gitee.com/leon19910505/ohmyzsh/raw/master/bee-project/nginx_pro.conf
curl -s -o ngx_conf/nginx/phase/init-by-lua-pro.lua https://gitee.com/leon19910505/ohmyzsh/raw/master/bee-project/init-by-lua-pro.lua
curl -s -o switch.sh https://gitee.com/leon19910505/ohmyzsh/raw/master/bee-project/switch.sh

chmod +x switch.sh

echo "\n\n\n\n"
echo "⭐️配置文件已下载，可以通过 sudo docker compose up -d 启动蜜蜂容器 \n"
echo "⭐️切换测试环境：  sudo ./switch.sh test \n"
echo "⭐️切换生产环境：  sudo ./switch.sh pro \n"

echo "⭐️下一步，修改服务器nginx转发到你这个容器的端口上，即可通过你的自定义子域名进行访问⭐️"